
$.validator.setDefaults({
	//submitHandler: function() { alert("submitted!"); },
	showErrors: function(map, list) {
		// there's probably a way to simplify this
		var focussed = document.activeElement;
		if (focussed && $(focussed).is("input, textarea")) {
			$(this.currentForm).tooltip("close", { currentTarget: focussed }, true)
		}
		this.currentElements.removeAttr("title").removeClass("ui-state-highlight");
		$.each(list, function(index, error) {
			$(error.element).attr("title", error.message).addClass("ui-state-highlight");
		});
		if (focussed && $(focussed).is("input, textarea")) {
			$(this.currentForm).tooltip("open", { target: focussed });
		}
	}
});

(function() {
	// use custom tooltip; disable animations for now to work around lack of refresh method on tooltip
	$("#signupForm").tooltip({
		show: false,
		hide: false
	});

	// validate signup form on keyup and submit
	$("#signupForm").validate({
		rules: {
			id: "required",
			nombre: "required",                        
			descripcion: {
				required: true,
				minlength: 2
			},
			precio: {
				required: true,
				minlength: 2
			}
		},
		messages: {
			id: "Por favor, ingrese el id.",
			nombre: "Por favor, ingrese el nombre.",
			descripcion: {
				required: "Por favor, ingrese la descripcion.",
				minlength: "Debe ingresear al menos 2 digitos."
			},
			precio: {
				required: "Por favor, ingrese precio.",
				minlength: "Debe ingresar al menos 2 digitos."
			}
		}
	});
	//code to hide topic selection, disable for demo
	

	$("#signupForm input:not(:submit)").addClass("ui-widget-content");

	$(":submit").button();
})();

